package com.cf.web.autoconfigure;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by zhumingming on 2018/6/14.
 */
@Configuration
@ConfigurationProperties(prefix = "zmm.web")
public class WebCommonProperty implements InitializingBean {


    /**
     * 扫描的目录
     */
    private String docPackage = "com.cf";

    /**
     * 文档的名字
     */
    private String docName = "文档的名字";

    /**
     * 文档的信息
     */
    private String docInfo = "接口文档说明";

    /**
     * 接口的版本
     */
    private String docVersion = "v1.0";

    /**
     * 错误地址
     */
    private String errorPage;


    private String ignorePath;

    /**
     * 忽略的地址
     */
    private List<String> ignore = new ArrayList<String>(Arrays.asList("/js", "/swagger", "/x-admin", "/login.html", "/shell.html"));


    /**
     * 添加忽略的地址
     *
     * @param ignore
     */
    public void registorIgonre(String ignore) {
        this.ignore.add(ignore);
    }

    public List<String> getIgnore() {
        return ignore;
    }

    public void setIgnore(List<String> ignore) {
        this.ignore.addAll(ignore);
    }

    public String getErrorPage() {
        return errorPage;
    }

    public void setErrorPage(String errorPage) {
        this.errorPage = errorPage;
    }

    public String getDocVersion() {
        return docVersion;
    }

    public void setDocVersion(String docVersion) {
        this.docVersion = docVersion;
    }

    public String getDocPackage() {
        return docPackage;
    }

    public void setDocPackage(String docPackage) {
        this.docPackage = docPackage;
    }

    public String getDocName() {
        return docName;
    }

    public void setDocName(String docName) {
        this.docName = docName;
    }

    public String getDocInfo() {
        return docInfo;
    }

    public void setDocInfo(String docInfo) {
        this.docInfo = docInfo;
    }

    public String getIgnorePath() {
        return ignorePath;
    }

    public void setIgnorePath(String ignorePath) {
        this.ignorePath = ignorePath;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (StringUtils.isNotEmpty(ignorePath)) {
            String[] split = ignorePath.split(",");
            this.ignore.addAll(Arrays.asList(split));
        }
    }
}
